<template>
  <button @click="xkprint('pdf')">导出pdf</button>
  <button @click="xkprint('print')">打印</button>
  <button @click="excelExport">导出excel</button>
  <button @click="customPrint">自定义打印</button>
  <button @click="previewPrint">打印预览</button>
  <button @click="updateConfigAndData">update</button>
  <div id="containerxzSortInGroup"></div>
</template>
<script setup>
import {onMounted} from 'vue';

import {
  sheetConfig_sortInGroup,
  data_sortInGroup,
  option_sortInGroup,
  reportPrintOptions_sortInGroup
} from "@/views/report/XzReport_sortInGroup_sheetConfig.js"

let spreadSheet
let reportPrint = XZReportPrint();

function updateConfigAndData() {
  try {
    spreadSheet.update(sheetConfig_sortInGroup, data_sortInGroup);
  } catch (error) {
    console.log(error);
  }

}

onMounted(() => {

  try {
    spreadSheet = XZReport("#containerxzSortInGroup", option_sortInGroup);
    spreadSheet.update(sheetConfig_sortInGroup, data_sortInGroup);
    reportPrint.setTemplate(reportPrintOptions_sortInGroup);

  } catch (error) {
    console.log(error);
  }

});

function xkprint(printmode) {
  //提供了两种打印方法, 表格实例直接调用即可
//  print 方法
// option 可选值  {mode:"print"}  print:直接打印 pdf:转pdf打印
  reportPrintOptions_sortInGroup.mode = printmode
  spreadSheet.print({mode: "print"});

// implicitPrint 方法   参数同pivotData方法
// data 传入二维数组是批量数据打印
// option 可选值  {mode:"print"}  print:直接打印 pdf:转pdf打印
  // spreadSheet.implicitPrint(sheetConfig,data,option?)

}

function excelExport() {

// @param {*} options {fileName: 'download', // 下载文件名 exportHideCol: true, // 是否导出隐藏的行列 exportFormula: true, // 是否导出公式

  spreadSheet.exportExcel({fileName: 'excel1', exportHideCol: true, exportFormula: true})
}

function customPrint() {
  console.log("reportPrint.getTemplate---->", reportPrint.getTemplate);
  reportPrint.print(reportPrintData);


}

function previewPrint() {
  reportPrint.previewPrint(reportPrintData);
}
</script>

<style scoped>

</style>
